//
//  ViewController.m
//  HDMusicDemo
//
//  Created by Lida on 2017/8/14.
//  Copyright © 2017年 Lida. All rights reserved.
//

#import "ViewController.h"
#import "AppDelegate.h"
#import "PlayerViewController.h"
#import "HD_LiDa_Playermanager.h"
#import "HD_LiDa_PlayerTool.h"
@interface ViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (strong, nonatomic) UITableView *listTableView;
@property (nonatomic,strong) HD_LiDa_Playermanager *playmanager;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    _playmanager = [HD_LiDa_Playermanager sharedHD_LiDa_Playermanager];
    [self initViews];
    
}

- (void)initViews
{
    //歌曲列表
    self.listTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height-80) style:UITableViewStylePlain];
    self.listTableView.delegate = self;
    self.listTableView.dataSource = self;
    [self.view addSubview:self.listTableView];
    
}

#pragma UITableView DataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _playmanager.allMusicArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *identifier = @"cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell==nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    
    MusicInfo *mode = _playmanager.allMusicArr[indexPath.row];
    cell.textLabel.text = mode.musicName;
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    MusicInfo *mode = _playmanager.allMusicArr[indexPath.row];
    _playmanager.currentMusic = mode;
    HD_LiDa_PlayerTool *playTool =[HD_LiDa_PlayerTool sharedHD_LiDa_PlayerTool];
    [playTool prepareForPlayWithMusic:_playmanager.currentMusic];
    [playTool play];
    
    PlayerViewController *playerVC = [[PlayerViewController alloc]init];
    [self presentViewController:playerVC animated:YES completion:nil];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
